//
//  SecondViewController.m
//  29-tableView_Animation
//
//  Created by Snow on 16/8/23.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "SecondViewController.h"

@interface SecondViewController ()<UITableViewDelegate, UITableViewDataSource>
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    self.view.backgroundColor = [UIColor whiteColor];
    self.imageOfSecond = [[UIImageView alloc] initWithFrame:_cgrect];
    self.imageOfSecond.image = [UIImage imageNamed:@"listen"];
    [self.view addSubview:self.imageOfSecond];
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 200, self.view.frame.size.width, self.view.frame.size.height -200) style:UITableViewStylePlain];
    [self.view addSubview:self.tableview];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
    self.tableview.transform = CGAffineTransformMakeTranslation(0, 375);
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [UIView animateWithDuration:3 animations:^{
        [_imageOfSecond layoutIfNeeded];
        _tableview.transform = CGAffineTransformIdentity;
    }];
    [UIView animateWithDuration:2 animations:^{
        _imageOfSecond.frame = CGRectMake(0, 0, self.view.frame.size.width, 200);
    } completion:^(BOOL finished) {
        
    }];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [UIView animateWithDuration:1 animations:^{
    [_imageOfSecond layoutIfNeeded];
    _tableview.alpha = 0;
} completion:^(BOOL finished) {
    
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.textLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
